home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 011 / adikit.arc / PPDRV.C < prev    next >
Encoding:
C/C++ Source or Header  |  1986-12-01  |  3.9 KB  |  159 lines

  1. /*
  2.     PPDRV  --  Test    ADI printer plotter driver
  3.  
  4.     This driver can    either print a printer plot binary file
  5.     written    by the generic printer plotter code or be installed
  6.     as a resident driver.
  7. */
  8.  
  9. #include <stdio.h>
  10.  
  11. #define    VECTOR 0x7B           /* Interrupt    vector for installation    */
  12.  
  13. #define    FALSE 0
  14. #define    TRUE 1
  15.  
  16. #define    putprint(q) bdos(5, q)       /* Send character to    printer    */
  17.  
  18. /*  Command codes for processing routine  */
  19.  
  20. #define    FILELEVEL   1           /* Generic plot file    format level */
  21.  
  22. #define    BEGINPLOT   0x8001       /* Begin plot */
  23. #define    ENDPLOT        0x8002       /* End of plot */
  24. #define    ABORTPLOT   0x8003       /* Plot terminated by user */
  25.  
  26. static short install = FALSE;       /* Install as resident driver */
  27. static FILE *fp;           /* Input file pointer */
  28. static short gotfile = FALSE;       /* Obtained file flag */
  29. static char tbfr[132];
  30. static short icode;           /* Length / command code */
  31. struct pregs {
  32.     unsigned ax, bx, cx, dx;
  33. };
  34. static struct pregs r;
  35. static struct {
  36.     short level, xdots,    ydots, colour;
  37. cfg;
  38.  
  39. main(argc,argv)
  40. int argc; 
  41. char *argv[];
  42. {
  43.     short i, j,    m;
  44.     char *cp, opt;
  45.     register short c;
  46.     char bbuf[1000];           /* Bit buffer */
  47.  
  48.     for    (i=1; i    < argc;    i++) {
  49.     cp = argv[i];
  50.         if (*cp == '-') {
  51.         opt    = *(++cp);
  52.         if (islower(opt))
  53.         opt = toupper(opt);
  54.         switch (opt) {
  55.  
  56.             case 'I':
  57.         install    = TRUE;
  58.         break;
  59.  
  60.             case '?':
  61.         help();
  62.         exit();
  63.         }
  64.     } 
  65.     else {
  66.         if (gotfile) {
  67.                 printf("\nDuplicate file name.");
  68.         exit(1);
  69.         }
  70.         strcpy(tbfr, cp);
  71.             strcat(tbfr, ".prp");
  72.             if (fp = fopen(tbfr, "rb"))
  73.         gotfile    = TRUE;
  74.         else {
  75.                 printf("\nCannot open file %s", tbfr);
  76.         exit(1);
  77.         }
  78.     }
  79.     }
  80.     if (!gotfile & !install) {
  81.     help();
  82.     exit(1);
  83.     }
  84.  
  85.     if (install) {
  86.         fprintf(stderr, "Printer plotter driver installed at %03xh", VECTOR);
  87.     while (1) {
  88.         iwait(VECTOR, &r, &r);
  89.         icode = r.ax;
  90.         if (icode == ENDPLOT) {
  91.                 putprint('\14');     /* Form feed */
  92.                 fprintf(stderr, "\nEnd plot.\n");
  93.         } 
  94.         else if (icode == BEGINPLOT) {
  95.                 fprintf(stderr, "Begin plot: interface level %d.  %d by %d\n",
  96.         r.bx, r.cx, r.dx);
  97.         r.ax = TRUE;      /* Say initialised OK    */
  98.         r.bx = FALSE;      /* Select monochrome */
  99.         } 
  100.         else if (icode == ABORTPLOT) {
  101.                 fprintf(stderr, "\nPlot aborted.\n");
  102.         } 
  103.         else {
  104.         if (icode & 0x8000) {
  105.                     fprintf(stderr, "\n** Undefined control code %04xh **\n", icode);
  106.         }
  107.         if (icode) {
  108.             peek(r.cx, r.bx, bbuf, icode);
  109.             for    (i = 0;    i < icode; i++)
  110.             for (m = 0x80, j = 0; j    < 8; j++, m >>=    1)
  111.                             putprint((bbuf[i] & m) ? '*' : ' ');
  112.         }
  113.                 putprint('\n');
  114.         }
  115.     }
  116.     }
  117.  
  118.     while (TRUE) {
  119.     fread(&icode, sizeof icode, 1, fp);
  120.     if (icode == ENDPLOT) {
  121.             putprint('\14');     /* Form feed */
  122.             fprintf(stderr, "End plot.");
  123.         break;
  124.     } 
  125.     else if    (icode == BEGINPLOT) {
  126.         fread(&cfg,    sizeof cfg, 1, fp);
  127.             fprintf(stderr, "Begin plot: interface level %d.  %d by %d %s\n",
  128.         cfg.level, cfg.xdots, cfg.ydots,
  129.             cfg.colour ? "colour" : "monochrome");
  130.     } 
  131.     else {
  132.         if (icode &    0x8000)    {
  133.                 printf("\n** Undefined control code %04xh **", icode);
  134.         break;
  135.         }
  136.         if (icode)
  137.         fread(bbuf, icode, 1, fp);
  138.         for    (i = 0;    i < icode; i++)
  139.         for (m = 0x80, j = 0; j    < 8; j++, m >>=    1)
  140.                     putprint((bbuf[i] & m) ? '*' : ' ');
  141.             putprint('\n');
  142.     }
  143.     }
  144.  
  145.     fclose(fp);
  146. }
  147.  
  148. /*  HELP  --  Print information    on how to call    */
  149.  
  150. static help()
  151. {
  152.     printf("\nPPDRV  --  Printer plotter driver.  Call");
  153.     printf("\n           with PPDRV [options] input-file");
  154.     printf("\n");
  155.     printf("\n           Options:   -I   Install as INT %02xh",
  156.     VECTOR);
  157. }
  158.